/**
 * 角色表格
 */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Table, Icon, Popconfirm } from 'antd';
import { Link } from 'dva/router';
import moment from 'moment';
import getPagination from '../../components/pagination';
import { onSetItemDecorator } from '../../components/export';

const styles = {
	icon: {
		fontSize: '16px',
		marginRight: '1em'
	}
};

export const columns = [
	{
		title: '产品品类',
		dataIndex: 'name',
		key: 'name',
	},
	{
		title: '产品数量',
		dataIndex: 'productCount',
		key: 'productCount'
	},
	{
		title: '修改时间',
		dataIndex: 'utime',
		key: 'utime',
		render: text => moment(text).format('YYYY-MM-DD HH:mm:ss')
	},
	{
		title: '操作',
		key: 'opt'
	}
];

@onSetItemDecorator
class MyTable extends Component {
	constructor(props, context) {
		super(props, context);
		this.columns = columns.map(c => c.key !== 'opt' ? c : { ...c, render: this.renderOpt });
	}

	onChange = selectedRowKeys => {
		this.props.select(selectedRowKeys);
	};

	renderOpt = (t, data) => {
		return <a onClick={() => this.props.edit(data)}>详情</a>;
	}

	render() {
		const { list, selectKeys } = this.props;
		const rowSelection = {
			onChange: this.onChange,
			selectedRowKeys: selectKeys
		};
		return (
			<Table
				rowKey="id"
				dataSource={list}
				columns={this.getColumns(this.columns)}
				pagination={getPagination()}
				rowSelection={rowSelection}
			/>
		);
	}
}

MyTable.propTypes = {

};

export default MyTable;
